let fs = require('fs')
// 发布(送牛奶)  中间代理  订阅(订牛奶)   每送一次牛奶都把订牛奶的都送一遍
function Events(){
  this.callbacks = []
  this.results = []
}
// 订阅(订阅是收集函数)
Events.prototype.on = function(callback){
  this.callbacks.push(callback)
}
// 发布(执行函数)
Events.prototype.emit = function(data){
  this.results.push(data)
  this.callbacks.forEach(c=>c(this.results))
}

let e = new Events()
e.on(function(arr){
  console.log(arr);
  if(arr.length == 3){
    console.log(arr);
  }
})


fs.readFile('./name.txt','utf-8', function(err, data){
  e.emit(data)
})

fs.readFile('./age.txt','utf-8', function(err, data){
  e.emit(data)
})

fs.readFile('./age.txt','utf-8', function(err, data){
  e.emit(data)
})
